<script>
import option from '@/utils/option'

export default {
    functional: true,
    props: {
        field: Object,
        fieldModel: Object,
        debounceTime: 0
    },
    render: function (h, context) {
        const params = {
            field: context.props.field,
            fieldModel: context.props.fieldModel,
            debounceTime: context.props.debounceTime
        };

        let render = {}
        if (params.field.render) {
            render = params.field.render(h, params)
        } else {
            let opt = option(params.field.type, params)
            
            opt.ref = params.field.key
            if (params.field.attrs) Object.assign(opt.attrs, params.field.attrs)
            if (params.field.props) Object.assign(opt.props, params.field.props)
            if (params.field.on) Object.assign(opt.on, params.field.on)
            
            render = h(params.field.type, opt)
        }
        return render
    }
}
</script>

<style lang="less" scoped>

</style>
